package com.ruoyi.web.controller.surfacewater;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.surfacewater.domain.BusDataAnalysisReport;
import com.ruoyi.surfacewater.domain.ReportVo;
import com.ruoyi.surfacewater.service.ReportDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 报表数据
 */
@RestController
@RequestMapping("/surfacewater/reportData")
public class ReportDataController extends BaseController {

    @Autowired
    private ReportDataService reportDataService;

    /**
     * 报表管理
     * @return
     */
    @GetMapping("/getReportData")
    public TableDataInfo getReportData(ReportVo vo)
    {
        startPage();
        List<BusDataAnalysisReport> list = reportDataService.selectBusDataAnalysisReportList(vo);
        return getDataTable(list);
    }

    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(reportDataService.selectBusDataAnalysisReportById(id));
    }

    /**
     * 添加
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody BusDataAnalysisReport busDataAnalysisReport)
    {
        busDataAnalysisReport.setCteateby(getUsername());
        busDataAnalysisReport.setUserid(getUserId());
        busDataAnalysisReport.setCheckstate("0");
        return toAjax(reportDataService.insertBusDataAnalysisReport(busDataAnalysisReport));
    }

    /**
     * 修改报告单数据（自动日报和周报以及手工月报）
     */
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody BusDataAnalysisReport busDataAnalysisReport)
    {
        busDataAnalysisReport.setCheckstate("0");
        return toAjax(reportDataService.updateBusDataAnalysisReport(busDataAnalysisReport));
    }

    /**
     * 删除报告单数据（自动日报和周报以及手工月报）
     */
    @GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(reportDataService.deleteBusDataAnalysisReportByIds(ids));
    }

    /**
     * 审核
     */
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody BusDataAnalysisReport busDataAnalysisReport)
    {
        busDataAnalysisReport.setCheckuserid(getUserId());
        busDataAnalysisReport.setChecktime(DateUtils.dateFormat(new Date(),"yyyy-MM-dd HH:mm:ss"));
        return toAjax(reportDataService.updateBusDataAnalysisReport(busDataAnalysisReport));
    }

    /**
     * 报表发布
     */
    @GetMapping("/getReportRelease")
    public TableDataInfo getReportRelease(ReportVo vo)
    {
        startPage();
        vo.setCheckstate("1");
        List<BusDataAnalysisReport> list = reportDataService.selectBusDataAnalysisReportList(vo);
        return getDataTable(list);
    }
}
